package com.stud.system.sql;

/**
 * @author Stud
 * @title XXXXX
 * @desription XXXXX
 * @data 2022-09-28 9:28
 */
public class MenuSqlFactory {
    /**
     * 递归查询下级菜单,查询所有下级菜单ID
     *
     * @param menuId
     * @return
     */
    public static String recurseDown(Long menuId) {
        StringBuilder sb = new StringBuilder();
        sb.append(" with recursive menu_cte as ( ");
        sb.append("     select menu_id, parent_id ");
        sb.append("     from sys_menu where menu_id = " + menuId);
        sb.append("     union all ");
        sb.append("     select t.menu_id, t.parent_id from sys_menu t ");
        sb.append("     inner join menu_cte cte on t.parent_id = cte.menu_id ");
        sb.append(" ) ");
        sb.append(" select menu_id level from menu_cte ");
        return sb.toString();
    }
}
